import Vue from 'vue'
import VueRouter from 'vue-router'
import index from "@/views/home/index.vue";

Vue.use(VueRouter)

export const routes = [
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    name: 'login',
    component: () => import('@/views/login/index'),
    meta: { title: '登录' }
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register/index'),
    meta: { title: '注册' }
  },
  {
    path: '/forget',
    name: 'forget',
    component: () => import('@/views/forget/index'),
    meta: { title: '找回密码' }
  },
  {
    path: '/user',
    name: 'index',
    component: index,
    children: [
      {
        path:'all',
        name:'all',
        component: () => import('@/views/home/all/index'),
        meta: { title: '所有' }
      },
      {
        path:'message',
        name:'message',
        component: () => import('@/views/home/message/index'),
        meta: { title: '消息' }
      },
      {
        path:'mine',
        name:'mine',
        component: () => import('@/views/home/mine/index'),
        meta: { title: '我的' }
      },
      {
        path:'publish',
        name:'publish',
        component: () => import('@/views/home/publish/index'),
        meta: { title: '发布' }
      }
    ]
  },
  {
    path: '/post',
    name: 'post',
    component: () => import('@/views/post/index'),
    meta: { title: '帖子详情' }
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
